package pers.cz.mock;

import pers.cz.context.MyThreadLocals;
import pers.cz.util.CollectType;
import pers.cz.util.ColletExecutor;
import pers.cz.util.RedisConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @program: postgirl-collection-client
 * @description: JdcbMock
 * @author: Cheng Zhi
 * @create: 2022-02-15 15:30
 **/
public class InterfaceSQlMock {

    private static RedisConfig redisUtil = null;

    static {
        redisUtil = new RedisConfig();
    }

    public static void begin(Object sqlObject) {


        if (!(sqlObject instanceof String)) {
            return;
        }

        try {
            final String sqlFinal = sqlObject.toString();
            final String busiCode = MyThreadLocals.context.get();
            final Long  currentTime = System.currentTimeMillis();
            ColletExecutor executor = ColletExecutor.getInstance(CollectType.INTERFACE_COLLECT);
            JedisPool jedisPool = redisUtil.redisPoolFactory();
            Jedis resource = jedisPool.getResource();
            executor.executeTask(new InterfaceSqlThread(sqlFinal, busiCode, currentTime, resource));
        } catch (Exception e) {
            System.out.println("postgirl-colleticon-client 采集SQL 出错：" + e.getMessage());
        }
    }

}
